// ActivexDemoCtrl.cpp : Implementation of the CActivexDemoCtrl ActiveX Control class.

#include "stdafx.h"
#include "ActivexDemo.h"
#include "ActivexDemoCtrl.h"
#include "ActivexDemoPropPage.h"
#include "afxdialogex.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


IMPLEMENT_DYNCREATE(CActivexDemoCtrl, COleControl)



// Message map

BEGIN_MESSAGE_MAP(CActivexDemoCtrl, COleControl)
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()



// Dispatch map

BEGIN_DISPATCH_MAP(CActivexDemoCtrl, COleControl)
	DISP_FUNCTION_ID(CActivexDemoCtrl, "AddFun", dispidAddFun, AddFun, VT_I4, VTS_I4 VTS_I4)
END_DISPATCH_MAP()



// Event map

BEGIN_EVENT_MAP(CActivexDemoCtrl, COleControl)
END_EVENT_MAP()



// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CActivexDemoCtrl, 1)
	PROPPAGEID(CActivexDemoPropPage::guid)
END_PROPPAGEIDS(CActivexDemoCtrl)



// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CActivexDemoCtrl, "ACTIVEXDEMO.ActivexDemoCtrl.1",
	0xc4876fa4, 0xa2c8, 0x4fca, 0x97, 0x86, 0xbd, 0x92, 0x70, 0xff, 0x3e, 0x56)



// Type library ID and version

IMPLEMENT_OLETYPELIB(CActivexDemoCtrl, _tlid, _wVerMajor, _wVerMinor)



// Interface IDs

const IID IID_DActivexDemo = { 0x897C3734, 0x5FA, 0x4B61, { 0xBB, 0xE7, 0x60, 0xDF, 0xCC, 0x3C, 0xCE, 0x15 } };
const IID IID_DActivexDemoEvents = { 0x92382CB7, 0xDC9E, 0x44A5, { 0x87, 0xB7, 0xF8, 0x61, 0xD9, 0x16, 0x47, 0x1B } };


// Control type information

static const DWORD _dwActivexDemoOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CActivexDemoCtrl, IDS_ACTIVEXDEMO, _dwActivexDemoOleMisc)



// CActivexDemoCtrl::CActivexDemoCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CActivexDemoCtrl

BOOL CActivexDemoCtrl::CActivexDemoCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_ACTIVEXDEMO,
			IDB_ACTIVEXDEMO,
			afxRegApartmentThreading,
			_dwActivexDemoOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}



// CActivexDemoCtrl::CActivexDemoCtrl - Constructor

CActivexDemoCtrl::CActivexDemoCtrl()
{
	InitializeIIDs(&IID_DActivexDemo, &IID_DActivexDemoEvents);
	// TODO: Initialize your control's instance data here.
}



// CActivexDemoCtrl::~CActivexDemoCtrl - Destructor

CActivexDemoCtrl::~CActivexDemoCtrl()
{
	// TODO: Cleanup your control's instance data here.
}



// CActivexDemoCtrl::OnDraw - Drawing function

void CActivexDemoCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	if (!pdc)
		return;

	// TODO: Replace the following code with your own drawing code.
	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	pdc->Ellipse(rcBounds);
}



// CActivexDemoCtrl::DoPropExchange - Persistence support

void CActivexDemoCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.
}



// CActivexDemoCtrl::OnResetState - Reset control to default state

void CActivexDemoCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}



// CActivexDemoCtrl message handlers


LONG CActivexDemoCtrl::AddFun(LONG num1, LONG num2)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// TODO: Add your dispatch handler code here
	long result = num1+num2;
	return result;
}
